package com.ms.game.common.utility;

import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xpec.c4.game.utility.GUID;

public class BenchMark 
{
	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(BenchMark.class);
	
	
	private static ConcurrentHashMap<GUID , BenchMarkData> benchMap 
													= new ConcurrentHashMap<GUID , BenchMarkData>();
	
	public synchronized  static void onStartBench(GUID sessionid , String messagetype)
	{
		BenchMarkData data = new BenchMarkData();
		data.messagetype = messagetype;
		benchMap.put(sessionid, data);
	}
	
	
	public synchronized static void onEndBench(GUID sessionid)
	{
		if(!benchMap.containsKey(sessionid))
		{
			if(log.isDebugEnabled())
			{
				log.debug("<<BenchMark>> Bench Key Not Find On SessionID : " + sessionid);
			}
			return;
		}
		
		BenchMarkData data = benchMap.get(sessionid);
		double wastertime = data.getWasteTime() / 1000;
		if(log.isDebugEnabled())
		{
			log.debug("<<BenchMark>> Bench Time On SessionID : " + sessionid + " MessageType : " + data.messagetype + " Waste Time : "+ wastertime + " Sec");
		}
		
		benchMap.remove(sessionid);
	}

}
